<?php
class teacher extends CI_Controller 
{
	public function __construct(){
		parent::__construct();
	}
	
	public function get_teacher_link($page = null){
		die('ok');
		$pattern = '/<tr logr=[^>]+?>\s+<td[^>]+?>\s+<b[^>]+?>([^<]+?)\s+:\s+<\/b>\s+<a href="([^"]+?)" target[^>]+?>([^<]+?)<\/a>/i';
		$url = $page ? $page : 'http://bj.58.com/fudao/d2/';
		$html = file_get_contents($url);
		//mat 1=>老师名 2=>链接地址 3=>标题名
		if(preg_match_all($pattern, $html, $mat)){
//			print_r($mat);
			$tnames=$links=$titles = $setarr = array();
			$tnames=$mat[1];
			$links = $mat[2];
			$titles = $mat[3];
			
			foreach ($tnames as $k=>$v){
				$setarr = array(
					'tname'	=> $v,
					'title'	=> trim($titles[$k]),
					'link'	=> trim($links[$k])
				);
				if($this->db->insert('teacher_page', $setarr)){
					echo '开始写入', $v, '  <br />';
				}
			}
		}else{
			echo '未匹配';
		}
		
	}
}